
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

class Solution
{
    int res = 0;
    int m = 0, n = 0;
    int dx[4] = { -1, 1, 0, 0 };
    int dy[4] = { 0, 0, -1, 1 };
public:
    int numIslands(vector<vector<char>>& grid)
    {
        m = grid.size(), n = grid[0].size();
        vector<vector<bool>> vis(m, vector<bool>(n, false));

        for (int i = 0; i < m; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                if (!vis[i][j] && '1' == grid[i][j])
                {
                    ++res;
                    _numIslands(grid, vis, i, j);

                }
            }
        }

        return res;
    }

private:
    void _numIslands(const vector<vector<char>>& grid, vector<vector<bool>>& vis, int row, int col)
    {
        if (!vis[row][col] && '1' == grid[row][col])
        {
            vis[row][col] = true;

            for (int k = 0; k < 4; ++k)
            {
                int x = row + dx[k], y = col + dy[k];
                if (x >= 0 && x < m && y >= 0 && y < n && !vis[x][y] && '1' == grid[x][y])
                {
                    _numIslands(grid, vis, x, y);
                }
            }
        }
    }
};

class RecentCounter
{
public:
    RecentCounter()
    {}

    int ping(int t)
    {
        for (_q.push(t); _q.size() && _q.front() < t - 3000;)
        {
            _q.pop();
        }

        return _q.size();
    }

private:
    queue<int> _q;
};

#if 0
class RecentCounter
{
public:
    RecentCounter()
    {}

    int ping(int t)
    {
        _v.push_back(t);
        auto low = lower_bound(_v.begin() + _left, _v.end(), t - 3000);
        _left = low - _v.begin();

        return _v.end() - low;
    }

private:
    int _left = 0;
    vector<int> _v;
};
#endif

void Test1()
{
    int a[] = { 1, 2, 3 };
    int b[3] = { 1, 2, 3 };
    int c[6] = { 1, 2, 3 };
}

int main()
{
    Test1();

	return 0;
}